package com.monster.mechanic.utils.resources;

import java.io.InputStream;
import java.util.Properties;


public class HibernateConfigProperties {
	
	
	 private static final String FILE_PROPERTIES = "/hibernate_config.properties";
	  private static HibernateConfigProperties instance;
	  private static Object mutex;
	  private Properties properties;

	  static {
	    mutex = new Object();
	  }
	  
	  private HibernateConfigProperties() {
	    load();
	  }
	  
	  public static HibernateConfigProperties getInstance() {
	    if (instance == null) {
	      synchronized (mutex) {
	        if (instance == null)
	          instance=new HibernateConfigProperties();
	      }
	    }
	    return instance;
	  }
	  
	  private void load() {    
	    try {
	      InputStream is = this.getClass().getResourceAsStream(FILE_PROPERTIES);
	      this.properties = new Properties();
	      this.properties.load(is);      
	    }
	    catch (Exception e) {
	      //Error.mensaje(e,"Estar seguro que esta en el CLASSPATH ".concat(INIT).concat(".properties"));
	    }
	  }
	  
	  public String getProperty(String id) {
	    String regresar = null;
	    try {
	      regresar= this.properties.getProperty(id);
	    }
	    catch (Exception e) {      
	      regresar="";
	    }
	    return regresar;
	  }
	  
	  public String getServerProperty(String id) {
	    try {
	      String servidor = this.properties.getProperty("application.server");
	      id = id.concat(".").concat(servidor);
	      return this.properties.getProperty(id);
	    }
	    catch (Exception e) {      
	    } // try
	    return null;
	  }

}
